var express = require('express'); //引入express模块  
var app = express();

var bodyParser = require('body-parser'); //request对象解析
var cookieParser = require('cookie-parser'); //request操作cookie
// app.use(function(req,res, next) {
//     req.on("data",function (chunk) {
//     	console.log("datra:",chunk.toString())
//     })
//     next();
// })
app.use(bodyParser());
app.use(cookieParser());
var server = require('http').createServer(app);
// var io = require('socket.io').listen(server); //引入socket.io模块并绑定到服务器

var multipart = require('connect-multiparty'); // form-data,req.files
app.use(multipart());

var MongoClient = require('mongodb').MongoClient;
global.co = require("co");
global.ObjectId = require('mongodb').ObjectID;
// co(function*() {
// 	var db = MongoClient.connect("mongodb://localhost:27017/test");
// 	var c=db.conection("local");
// 	console.log(c);
// });
MongoClient.connect("mongodb://localhost:27017/menstruation", function(err, db) {
    // var c = db.collection("local");
    // console.log(connection);
    global.db = db;

    var router = require("./router")(app); // 路由指定路径
    // db.moods.save({mood:"hehe"});
    // db.close()
});
server.listen(1314); //指定服务端口在1104
/*
 * socket通信部分
 */
console.log("server started in 1314");
